package com.yonyou.pmclouds.outter.controller;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yonyou.pmclouds.basecom.view.DisableWrap;
import com.yonyou.yht.sdk.UserCenter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/outter/yht")
public class YHTCallBackController {

    private ObjectMapper objectMapper = new ObjectMapper();
    @GetMapping("/checkToken")
    @DisableWrap
    public String checkToken(String token)
    {
        String validateResult = UserCenter.getUserByLoginName(token);
        Map checkResultMap = null;
        try {
            checkResultMap = objectMapper.readValue(validateResult, Map.class);
        } catch (Exception e) {

        }
        JSONObject json = new JSONObject();
        json.put("mobile",token);
        json.put("username", ((Map) checkResultMap.get("user")).get("userName"));
        json.put("identify", ((Map) checkResultMap.get("user")).get("userId"));
        return json.toJSONString();
    }
}
